<template>
  <div>
      <h4>商品分类</h4>
    <div id="box"></div>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import * as echarts from "echarts";
export default {
  props: [],
  components: {},
  data() {
    return {};
  },
  watch: {
    cateList: {
      handler() {
        var myChart = echarts.init(document.getElementById("box"));
        var option = {
          xAxis: {
            type: "category",
            data: this.cateList.map((item) => item.catename),
          },
          yAxis: {
            type: "value",
          },
          series: [
            {
              data: this.cateList.map((item) => item.children.length),
              type: "line",
            },
          ],
        };
        myChart.setOption(option);
      },
      deep: true,
    },
  },
  computed: {
    ...mapGetters({
      cateList: "cate/list",
    }),
  },
  methods: {
    ...mapActions({
      reqCateList: "cate/reqChangeList",
    }),
  },
  mounted() {
    this.reqCateList();
  },
};
</script>

<style scoped>
h4{
    margin-left: 10%;
    color: rgb(247, 75, 22);
}
#box {
  width: 80%;
  height: 400px;
  border: 1px solid #ccc;
  /* margin-top: 4%; */
  margin-left: 10%;
}
</style>